package com.haixiaoke.saas.enterprise.contract.controller;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.contract.domain.HouseCommission;
import com.haixiaoke.saas.contract.service.IHouseCommissionService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 房屋委托信息Controller
 *
 * @author xiaolong
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/enterprise/contract/commission")
public class EnterpriseHouseCommissionController extends BaseController {
    @Autowired
    private IHouseCommissionService houseCommissionService;

    /**
     * 查询房屋委托信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseCommission houseCommission) {
        startPage();
        List<HouseCommission> list = houseCommissionService.selectHouseCommissionList(houseCommission);
        return getDataTable(list);
    }

    /**
     * 导出房屋委托信息列表
     */
    @PostMapping("/export")
    @RepeatSubmit
    public void export(HttpServletResponse response, HouseCommission houseCommission) {
        List<HouseCommission> list = houseCommissionService.selectHouseCommissionList(houseCommission);
        ExcelUtil<HouseCommission> util = new ExcelUtil<HouseCommission>(HouseCommission.class);
        util.exportExcel(response, list, "房屋委托信息数据");
    }

    /**
     * 获取房屋委托信息详细信息
     */
    @GetMapping(value = "/{houseCommissionId}")
    public AjaxResult getInfo(@PathVariable("houseCommissionId") Long houseCommissionId) {
        return success(houseCommissionService.selectHouseCommissionByHouseCommissionId(houseCommissionId));
    }

    /**
     * 新增房屋委托信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:commission:add')")
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody @Valid HouseCommission houseCommission) {
        houseCommission.setCreateBy(getUserId().toString());
        return toAjax(houseCommissionService.insertHouseCommission(houseCommission));
    }

    /**
     * 修改房屋委托信息
     */
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody HouseCommission houseCommission) {
        return toAjax(houseCommissionService.updateHouseCommission(houseCommission));
    }

    /**
     * 删除房屋委托信息
     */
    @DeleteMapping("/{houseCommissionIds}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] houseCommissionIds) {
        return toAjax(houseCommissionService.deleteHouseCommissionByHouseCommissionIds(houseCommissionIds));
    }
}
